package com.cloud.spider.dtos;

import java.util.Objects;

/**
 * @author 柳晓宇
 * @description 章节链接
 * @create 2023/8/5
 */
public class ChapterLinkDto implements Comparable{
//    private String pageUri; // 分页索引 放弃使用 因为无法去重，即使正文uri一样，但是不在一个分页
    private String uri; // 正文 uri
    private String title; // 标题

    public ChapterLinkDto(String title, String uri) {
        this.title = title;
        this.uri = uri;
    }
    public String getTitle() {
        return title;
    }

    public String getUri() {
        return uri;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public void setUri(String uri) {
        this.uri = uri;
    }

    @Override
    public String toString() {
        return "ContentLinkDto{" +
                "uri='" + uri + '\'' +
                ", title='" + title + '\'' +
                '}';
    }


    @Override
    public int compareTo(Object o) {
        // 对象
        if (o == this){
            return 0;
        }
        if (o instanceof ChapterLinkDto) {
            ChapterLinkDto obj = (ChapterLinkDto) o;

            return this.uri.compareTo(obj.getUri());
        }

        throw new RuntimeException("排序出现异常");
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ChapterLinkDto that = (ChapterLinkDto) o;
        return Objects.equals(uri, that.uri) && Objects.equals(title, that.title);
    }

    @Override
    public int hashCode() {
        return Objects.hash(uri, title);
    }
}
